#!/usr/bin/env python3
import time
import os
import sys

# 使用 Unicode 方块
BLOCK = '█'
SPACE = ' '

# 简单的数字字体（5行高）
DIGITS = {
    '0': [
        '███',
        '█ █',
        '█ █',
        '█ █',
        '███',
    ],
    '1': [
        '  █',
        '  █',
        '  █',
        '  █',
        '  █',
    ],
    '2': [
        '███',
        '  █',
        '███',
        '█  ',
        '███',
    ],
    '3': [
        '███',
        '  █',
        ' ██',
        '  █',
        '███',
    ],
    '4': [
        '█ █',
        '█ █',
        '███',
        '  █',
        '  █',
    ],
    '5': [
        '███',
        '█  ',
        '███',
        '  █',
        '███',
    ],
    '6': [
        '███',
        '█  ',
        '███',
        '█ █',
        '███',
    ],
    '7': [
        '███',
        '  █',
        '  █',
        '  █',
        '  █',
    ],
    '8': [
        '███',
        '█ █',
        '███',
        '█ █',
        '███',
    ],
    '9': [
        '███',
        '█ █',
        '███',
        '  █',
        '███',
    ],
    ':': [
        '   ',
        ' █ ',
        '   ',
        ' █ ',
        '   ',
    ],
}

def clear():
    # 兼容性强的清屏方式
    print("\033[H\033[J", end='')

def render_time(time_str):
    # time_str: e.g. "23:59"
    lines = ['' for _ in range(5)]
    for char in time_str:
        digit = DIGITS.get(char, ['   '] * 5)
        for i in range(5):
            # 替换空格为 SPACE，字符为 BLOCK
            line = ''.join(BLOCK if c == '█' else SPACE for c in digit[i])
            lines[i] += line + SPACE * 2
    return lines

def main():
    try:
        while True:
            # now = time.strftime('%H:%M')
            now = time.strftime('%H:%M:%S')
            clear()
            lines = render_time(now)
            for line in lines:
                print(line)
            time.sleep(1)
    except KeyboardInterrupt:
        print("\nbye~")
        sys.exit(0)

if __name__ == '__main__':
    main()
